﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.Diagnostics;

namespace EagleJournalBE.Database
{
    class EDIT
    {
        public void updateClient(int idnum,String  name)
        {

            try
            {
                MySqlConnection myConnection;
                string server;
                string database;
                string uid;
                string password;
                //MySqlDataReader dataReader;
                string query = "UPDATE client SET clientname='"+name+"',' WHERE clientid ='" + idnum + "';";
                server = "localhost";
                database = "travel_cmp_db";
                uid = "root";
                password = "p@ssword";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

                myConnection = new MySqlConnection(connectionString);
                myConnection.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = query;
                cmd.Connection = myConnection;
                cmd.ExecuteNonQuery();
                myConnection.Close();

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
        public void updateClientContact(int contactid, String contacttype, String contactValue)
        {

            try
            {
                MySqlConnection myConnection;
                string server;
                string database;
                string uid;
                string password;
                //MySqlDataReader dataReader;
                string query = "UPDATE clientcontact SET contacttype='" + contacttype + "', contactValue='" + contactValue + "', WHERE clientcontactId ='" + contactid + "';";
                server = "localhost";
                database = "travel_cmp_db";
                uid = "root";
                password = "p@ssword";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

                myConnection = new MySqlConnection(connectionString);
                myConnection.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = query;
                cmd.Connection = myConnection;
                cmd.ExecuteNonQuery();
                myConnection.Close();

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
        public void updateClientAffectedbyCLIENTID(int POid,int ClientId)
        {

            try
            {
                MySqlConnection myConnection;
                string server;
                string database;
                string uid;
                string password;
                //MySqlDataReader dataReader;
                string query = "UPDATE ClientsAffected SET POID='" +POid+ "',  WHERE CLIENTID ='" + ClientId + "';";
                server = "localhost";
                database = "travel_cmp_db";
                uid = "root";
                password = "p@ssword";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

                myConnection = new MySqlConnection(connectionString);
                myConnection.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = query;
                cmd.Connection = myConnection;
                cmd.ExecuteNonQuery();
                myConnection.Close();

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }

        public void updateClientAffectedbyPOID(int POid, int ClientId)
        {

            try
            {
                MySqlConnection myConnection;
                string server;
                string database;
                string uid;
                string password;
                //MySqlDataReader dataReader;
                string query = "UPDATE ClientsAffected SET ClientId='" + ClientId + "',  WHERE POID ='" + POid + "';";
                server = "localhost";
                database = "travel_cmp_db";
                uid = "root";
                password = "p@ssword";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

                myConnection = new MySqlConnection(connectionString);
                myConnection.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = query;
                cmd.Connection = myConnection;
                cmd.ExecuteNonQuery();
                myConnection.Close();

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }

        public void updatePO(int POid,int POserail,String clientName,DateTime date,float amount,String company,String description,int clientID)
        {

            try
            {
                MySqlConnection myConnection;
                string server;
                string database;
                string uid;
                string password;
                //MySqlDataReader dataReader;
                string query = "UPDATE purchaseOrder SET purchaseOrderSerial='" + POserail + "', clientName='" + clientName + "', dateIssued='" + date + "', amount='" + amount + "', company='" + company + "', description='" + description + "', clientid='" + clientID + "' WHERE clientid ='" + POid + "';";
                server = "localhost";
                database = "travel_cmp_db";
                uid = "root";
                password = "p@ssword";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

                myConnection = new MySqlConnection(connectionString);
                myConnection.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = query;
                cmd.Connection = myConnection;
                cmd.ExecuteNonQuery();
                myConnection.Close();

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
        public void updateDeadline(int clientid,int POid,DateTime date,bool status,int deadlineId)
        {

            try
            {
                MySqlConnection myConnection;
                string server;
                string database;
                string uid;
                string password;
                //MySqlDataReader dataReader;
                string query = "UPDATE deadline SET clientId='" + clientid + "',purchaseOrderId='" + POid + "',status='" + status + "' WHERE deadlineid ='" + deadlineId + "';";
                server = "localhost";
                database = "travel_cmp_db";
                uid = "root";
                password = "p@ssword";
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";

                myConnection = new MySqlConnection(connectionString);
                myConnection.Open();
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = query;
                cmd.Connection = myConnection;
                cmd.ExecuteNonQuery();
                myConnection.Close();

            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
        }
    }
}
 
